package bing.tij4.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * waits on CountDownLatch.
 * @author LBH
 *
 */
class WaitingTask implements Runnable{
	private static int counter=0;
	private final int id=counter++;
	
	private final CountDownLatch latch;
	WaitingTask(CountDownLatch latch){
		this.latch=latch;
	}
	
	public void run() {
		try {
			System.out.println(id+" start waiting");
			latch.await();
			System.out.println(id+"stop waiting");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			System.out.println(this+"interrupted");
		}
		
	}

	public String toString(){
		return String.format("WaitingTask %1$-3d ", id);
	}
}
